<template>
  <van-form @submit="onSubmit">
    <van-field
        v-model="account"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
    />
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>
</template>


<script setup lang="ts">
import {ref} from "vue";
import { useRouter} from "vue-router";
import request from '../../utils/request'
import {showToast} from 'vant';
import {login} from "../../services/api.ts";


const router = useRouter();
const account = ref('')
const password = ref('')


const onSubmit = async () => {

  const res = await login({
    account: account.value,
    password:password.value
  })
  // console.log(res)
  if (res.code === 0) {
    showToast(res.description);
    router.back()
  }

};
</script>


<style scoped>

</style>